package servlet;

import bean.Result;
import biz.BizException;
import biz.userBiz;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Map;

@WebServlet(name = "UpdatePwdServlet", value = "/updatepwd.s")
public class UpdatePwdServlet extends HttpServlet {

    userBiz biz=new userBiz();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        final HttpSession session = request.getSession();
        final String password = request.getParameter("pass");
        final Integer userid = (Integer) session.getAttribute("userid");
        Result result = null;
        try {
            biz.update(userid,password);

            result =new Result(1,"修改成功",null);
        } catch (BizException e) {
            e.printStackTrace();
        }
        final String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
